<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<?php $this->load->view('common/head'); ?>

<?php $this->load->view('common/header'); ?>
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <?php $this->load->view('common/sidebar'); ?>
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <?php $this->load->view('common/breadcrumbs'); ?>

            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">

                <?php $this->load->view('common/set'); ?>

                <!-- /section:settings.box -->
                <div class="row">
                    <form id="form2" class="form-inline" action="" method="get">
                        <?php echo csrf_hidden();?>
                        开始时间：<input type="text" class="form-control demo-input starttime" name='starttime' placeholder="开始日期" id="test1">
                        结束时间：<input type="text" class="form-control demo-input endtime" name='endtime' placeholder="结束日期" id="test2">
                        <span class="btn btn-purple btn-sm" id="excel">
                            <span class=" icon-on-right bigger-110"></span>
                            导出excel
                        </span>
                    </form>
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <table class="table table-striped table-bordered">
                            <thead>
                            <tr>
                                <th class="center"><input class="check-all" type="checkbox" value=""></th>
                                <th>下单日期</th>
                                <th>用戶</th>
                                <th>订单号</th>
                                <th>分期总金额</th>
                                <th>分期数</th>
                                <th>单笔状态</th>
                                <th>销售贷余额</th>
                                <!--                                <th class="center">操作</th>-->
                            </tr>
                            </thead>
                            <tbody>
                            <?php if ($logs) {
                                foreach ($logs as $key => $val) { ?>
                                    <tr>
                                        <td class="center">
                                            <input class="uids" type="checkbox" name="uids[]" value="{$val['uid']}">
                                        </td>
                                        <td><?php echo $val['ctime']; ?></td>
                                        <td><?php echo $val['user_name']; ?></td>
                                        <td><?php echo $val['order_no']; ?></td>
                                        <td><?php echo $val['order_cost']; ?></td>
                                        <td><?php echo $val['stage_num'] ?? 3; ?></td>
                                        <td class="center">
                                            <?php if ($val['is_return'] == 0) { ?>
                                                未还款
                                            <?php } ?>
                                            <?php if ($val['is_return'] == 1) { ?>
                                                <span class="label label-success arrowed arrowed-right">已还款</span>
                                            <?php } ?>
                                            <?php if ($val['is_return'] == 2) { ?>
                                                <span class="label label-warning arrowed arrowed-right">已分期</span>
                                            <?php } ?>
                                        </td>
                                        <td><?php echo $val['user_money_real']; ?></td>
                                        <!--                                    <td class="center">-->
                                        <!--                                        --><?php //if($val['is_return'] == 0){?>
                                        <!--                                            <a href="javascript:;" onclick="return_money(<?php //echo $val['id'];?>)">确认还款</a>&nbsp;&nbsp;
                                    --><?php //} ?>
                                        <!--                                        --><?php //if($val['is_return'] == 1){?>
                                        <!--                                            <span class="label label-warning arrowed arrowed-right">已还款</span>-->
                                        <!--                                        --><?php //} ?>
                                        <!--                                        --><?php //if($val['is_return'] == 2){?>
                                        <!--                                            <a href="-->
                                        <?php //echo site_url(X_URL.'member/money_stage/'.$val['id']);;?><!--">查看分期</a>&nbsp;&nbsp;-->
                                        <!--                                        --><?php //} ?>
                                        <!--                                    </td>-->
                                    </tr>
                                <?php }
                            } ?>
                            </tbody>
                        </table>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    <?php $this->load->view('common/footer'); ?>
</div><!-- /.main-container -->

<?php $this->load->view('common/footerjs'); ?>
<?php echo admin_js_url('laydate');?>
<!-- inline scripts related to this page -->
<script type="text/javascript">
    //执行一个laydate实例
    laydate.render({
        elem: '#test1' //指定元素
    });
    laydate.render({
        elem: '#test2' //指定元素
    });
    $("#excel").click(function () {
        var starttime = $("#test1").val();
        var endtime = $("#test2").val();
        var url = baseurl+"index.php/manage/member/export_excel";

        window.location.href=url+"?starttime="+starttime+"&endtime="+endtime;
    });
    function return_money(id) {

        var locationurl = baseurl + "index.php/manage/member/return_money";
        $.ajax({
            url: locationurl,
            type: "get",
            data: {'return_id': id},
            dataType: 'json',
            success: function (data) {
                console.log(data);
                if (data.code == 200) {
                    layer.msg('还款成功', {
                        time: 1000, //1s后自动关闭
                        shade: 0.1
                    }, function () {
                        window.location.href = window.location.href;
                    });
                } else {
                    console.log(data);
                    layer.msg(data.msg);
                }
            }
        });
    }


</script>
</body>
</html>
